# import pymysql
#
# conn=pymysql.connect(host='127.0.0.1',user='root',password='FW249746',database='homework')
#
# cur=conn.cursor()#游标,可以知道SQL语句走到哪一句话了
#
# cur.execute('select * from student;')
# # while True:
# #     ret=cur.fetchone()
# #     print(ret)
# # ret=cur.fetchmany(10)
# # print(ret)
# rets=cur.fetchall()
# for ret in rets:
#     print(ret)

import pymysql

conn=pymysql.connect(host='127.0.0.1',user='root',password='FW249746',database='homework')

cur=conn.cursor(cursor=pymysql.cursors.DictCursor)#游标,可以知道SQL语句走到哪一句话了
                    #元组变字典
try:
    cur.execute('select * from student;')
    # while True:
    #     ret=cur.fetchone()
    #     print(ret)
    # ret=cur.fetchmany(10)
    # print(ret)
    rets=cur.fetchall()
    print(cur.rowcount)
    for ret in rets:
        print(ret)
except pymysql.err.ProgrammingError as e:
    print(e)





